<?php
	$dt=time();
	$time_out = 1800;//15 minutes			
	$time_new = $dt - $time_out;			
	
	//clear old history login
	$sql = "update history_login set active = 0 where datetime < $time_new and active = 1";		
	$query=mysql_query($sql);
?>
<table border="0" width="100%" align="center">
<tr>
	<td align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Users login</span></td>
	<td align="right">&nbsp;</td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="2" height="11"></td>
</tr>    
</table>

<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td align="center" width="30">#</td>
	<td align="center" width="20"></td>
	<td align="center" width="180">Name</td>
    <td align="center" width="200">Email</td>
    <td align="center" width="150">University</td>
	<td align="center" width="150">IP Address</td>
    <td align="center">Date time</td>    
</tr>
</thead>
<?php
include('includes/function.php');
$self = "index.php?tc=users_login";
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

$sql_standard = "SELECT u.FirstName, u.LastName as Name, u.Email, h.university_name, h.ip_address, h.datetime " .
				"FROM history_login h INNER JOIN users u ON h.email = u.Email " .
				"WHERE active = 1 " .
				"ORDER BY h.datetime DESC";
if($st == "" || $st == 2)
{
	$res = mysql_query($sql_standard);
}

$sql = $sql_standard . " limit $offset , $rowsPerPage";
$query = mysql_query($sql);
$i = 1;
while($q = mysql_fetch_array($query))
{ 
	?>	
    <tr>	
        <td align="center"><?php echo $i+$offset;?></td>
		<td align="center" width="20"><img src="../images/dot-online.jpg"/></td>
        <td align="left"><?php echo trim($q["FirstName"] . " " . $q["LastName"]);?></td>
        <td align="left"><a href="mailto:<?php echo $q["Email"];?>"><?php echo $q["Email"];?></a></td>
        <td align="left"><?php echo $q["university_name"];?></td>
        <td align="left"><?php echo $q["ip_address"];?></td>
        <td align="center"><?php echo date("h:i:s m/d/Y", $q['datetime']);?></td>        
   	</tr>     
<?php 
	$i++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="13" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table> 